﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Model;
using System.Collections.Generic;
namespace DAL
{
    /// <summary>
    /// 数据访问类:PMS_ProjectEvolveAttachment
    /// </summary>
    public class PMS_ProjectEvolveAttachmentDAL
    {
        public PMS_ProjectEvolveAttachmentDAL()
        { }
        #region  Method

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PMS_ProjectEvolveAttachment model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMS_ProjectEvolveAttachment set ");
            strSql.Append("attachment=@attachment");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@attachment", SqlDbType.NVarChar,1000)};
            parameters[0].Value = model.id;
            if (string.IsNullOrEmpty(model.attachment))
            {
                parameters[1].Value = DBNull.Value;
            }
            else
            {
                parameters[1].Value = Comm.Config.UploadPath + "Evelve/" + model.attachment;
            }

            int rows = SqlHelper.ExecuteNonQuery(Comm.Config.PMS, CommandType.Text, strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PMS_ProjectEvolveAttachment> GetList(string projectID)
        {
            string sql = "select * FROM PMS_ProjectEvolveAttachment where isDelete='0' and projectID=@projectID order by orders";
            SqlParameter[] parameters = { new SqlParameter("@projectID", projectID) };
            return SqlHelper.GetDataByColumnsLst<PMS_ProjectEvolveAttachment>(Comm.Config.PMS, sql, parameters);
        }

        #endregion  Method
    }
}

